import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { EntityType } from "../../../rules/EntityType";
import { AIManager } from "../../../scene/ai/AIManager";
import { GameProxy } from "../../../mvc/GameProxy";
import { EPassType } from "../../../../../Message/Game/EPassType";
import { CopyConfig } from "../../../resource/CopyConfig";
import { Cache } from "../../../cache/Cache";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { CopyUtil } from "../CopyUtil";
import { ECopyWaitingOperate } from "../../../../../Message/Public/ECopyWaitingOperate";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { TaskTargetInfo } from "../../../model/TaskTargetInfo";
type int = number;
//class CopyGroupGatherPanel
    
    export  class CopyGroupGatherPanel extends BaseWindow
    {
        constructor()
        {
            super();
            this.setSize(330, 140);
            this.titleHeight = 25;
            this.title = ObjCreate.createTitleTextField(Language.getString(60063));
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(19, 42, 292, 50, this);
            this._minimizeBtn = ObjCreate.createGButton("", 280, 5, 19, 19, this, "MinimizeButton");
            this._minimizeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._descText = ObjCreate.createTextField("", 26, 48, 280, 70, this);
            this._descText.wordWrap = true;
            this._descText.defaultTextFormat = new GTextFormat(FontUtil.songtiName, null, GlobalStyle.color1Uint, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, 24, 5);
            this._autoPassBtn = ObjCreate.createGButton(Language.getString(60064), 70, 100, 70, 26, this);
            this._autoPassBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._autoFlyBtn = ObjCreate.createGButton(Language.getString(60065), 190, 100, 70, 26, this);
            this._autoFlyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget;
            switch (loc1) 
            {
                case this._minimizeBtn:
                {
                    this.dispatchEvent(new Object /* flash.events.Event */(CopyGroupGatherPanel.DoMinimize, true, false));
                    break;
                }
                case this._autoPassBtn:
                {
                    if (this.targetInfo) 
                    {
                        this.targetInfo.targetType = EntityType.Point;
                        AIManager.onAutoPathAIControl(this.targetInfo);
                    }
                    this.hide();
                    break;
                }
                case this._autoFlyBtn:
                {
                    if (this.copy) 
                    {
                        GameProxy.sceneProxy.pass(EPassType.convert(EPassType._EPassTypeToCopyNpc), this.copy.code, this._npcId, 1);
                    }
                    this.hide();
                    break;
                }
            }
            return;
        }

        public updateGatherInfo(arg1: int, arg2: int): void
        {
            this.copy = CopyConfig.instance.getInfoByCode(arg1);
            this._npcId = arg2;
            if (this.copy) 
            {
                this.targetInfo = Cache.instance.scene.getNpcByNpcId(this._npcId);
                if (this.targetInfo) 
                {
                    this._descText.htmlText = Language.getStringByParam(60066, HTMLUtil.addColor(this.copy.name, GlobalStyle.color6), HTMLUtil.addColor(this.targetInfo.mapName, GlobalStyle.color1), HTMLUtil.addColor(this.targetInfo.name, GlobalStyle.color6));
                }
            }
            return;
        }

        protected /* override */ closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.closeBtnClickHandler(arg1);
            if (this.copy) 
            {
                if (CopyUtil.isCrossCopy(this.copy)) 
                {
                    GameProxy.copy.enterCrossCopyWaitingRoom_async(this.copy.code, ECopyWaitingOperate._ECopyWaitingRefuseGather, this._npcId);
                }
                else 
                {
                    GameProxy.copy.enterCopyWaitingRoom_async(this.copy.code, ECopyWaitingOperate._ECopyWaitingRefuseGather, this._npcId);
                }
            }
            return;
        }

        public static /* const */DoMinimize: string="集合面板最小化";

        /* internal */ /* var */_minimizeBtn: GButton;

        /* internal */ /* var */_descText: Object /* flash.text.TextField */;

        /* internal */ /* var */_autoPassBtn: GButton;

        /* internal */ /* var */_autoFlyBtn: GButton;

        public /* var */copy: TCopy;

        public /* var */targetInfo: TaskTargetInfo;

        /* internal */ /* var */_npcId: int;
    }
